package leecode;

import java.util.Stack;

public class CQueue {
    Stack <Integer> stack1;
    Stack<Integer> stack2;

    public CQueue() {
        stack1 = new Stack<Integer>();
        stack2 = new Stack<Integer>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {

        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
        }
        if (stack2.isEmpty()) {
            return -1;
        } else {
            return stack2.pop();
        }
    }

    public static void main(String[] args) {
        CQueue c = new CQueue();
        c.appendTail(1);
        c.appendTail(2);
        c.appendTail(3);
        c.appendTail(4);
        System.out.println(c.stack1);
        System.out.println("********************");
        System.out.println(c.deleteHead());
        System.out.println(c.deleteHead());
        c.appendTail(5);
        System.out.println(c.deleteHead());
        System.out.println(c.deleteHead());
        System.out.println(c.deleteHead());
        System.out.println(c.deleteHead());
    }
}
